package com.example.demo.controller;

import com.example.demo.entity.SysRole;
import com.example.demo.repository.SysRoleRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Copyright(C), 2020-2021, AmbroseCdMeng
 * FileName:    SysRoleController
 * Author:      AmbroseCdMeng
 * Date:        2021/3/4 14:59
 * Description: 角色管理控制器
 * History:
 * <author>     <time>      <version>       <desc>
 * 作者姓名     修改时间        版本号           描述
 */
@Controller
@RequestMapping("admin")
public class SysRoleController {
    @Autowired
    private SysRoleRepository sysRoleRepository;

    @RequestMapping("/role/add")
    public String addRole() {
        return "admin/role/add";
    }

    @RequestMapping("/role")
    public String addRole(SysRole model) {
        String role = "ROLE_" + model.getRole();
        model.setRole(role);
        sysRoleRepository.save(model);
        return "redirect:/admin/";
    }
}
